// 展示历史核酸检测情况
<template>
    <el-table v-loading="loading" :data="nucleics" :row-class-name="tableRowClassName"
        :default-sort="{ prop: 'time', order: 'descending' }" height="650px">
        <el-table-column prop="time" sortable label="时间" />
        <el-table-column prop="username" sortable label="机构" />
        <el-table-column label="状态">
            <template v-slot="scope">
                {{ code2Status(scope.row.result) }}
            </template>
        </el-table-column>
    </el-table>
</template>

<script>
import { Request } from '../../utils/request'

export default {
    name: 'NucleicShow',
    data() {
        return {
            nucleics: [],
            loading: false
        };
    },
    created() {
        this.reload()
    },
    methods: {
        reload() {
            this.loading = true
            Request({
                url: '/nucleic-acid-test',
                method: 'get'
            }).then(res => {
                this.nucleics = res.record_list
                this.loading = false
            })
        },
        code2Status(code) {
            if(code === 3) return '未完成'
            else if(code === 2) return '已完成'
            else if(code === 1) return '阳性'
            else return '阴性'
        },
        tableRowClassName({row}) {
            console.log(row.result)
            if(row.result === 1) return 'danger-row'
            if(row.result === 0) return 'success-row'
            return ''
        }
    }
}
</script>

<style>
.el-table .danger-row {
    --el-table-tr-bg-color: var(--el-color-danger-light-9);
}
.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-light-9);
}
</style>